<?php
class AcademicsController extends AppController {

	var $name = 'Academics';
	var $helpers = array('Html', 'Form');

    function mylist()
    {
        $this->Academic->recursive=-1;
        return $this->Academic->find('all');
    }

	function index_admin() 
    {
        if($this->Session->read('User.type')=='admin')
        {
            $this->layout = 'ajax';
            if(!empty($this->data))
            { 
                if($this->data['Academic']['name'] == '' )
                {
                    $this->set('empty',true);
                }
                else
                if(!empty($this->data['Academic']['id']))
                {
                    $count = $this->Academic->find('count',array('conditions'=>array('Academic.name'=>$this->data['Academic']['name'],'Academic.id <>'=>$this->data['Academic']['id'])));
                    if( $count == 0 ) 
                    { $this->Academic->save($this->data); }
                    else
                    { $this->set('wrong',true); } 
                }
                else
                {
                    $count = $this->Academic->find('count',array('conditions'=>array('Academic.name'=>$this->data['Academic']['name'])));
                    if( $count == 0 ) 
                    { $this->Academic->create(); $this->Academic->save($this->data); }                
                    else
                    { $this->set('wrong',true); }
                }
            }
            $this->Academic->recursive=-1;
            $academics = $this->Academic->find('all',array('order'=>'Academic.id'));
            $this->set('academics',$academics);
        } 	
    }
                    
    function delete_admin($id)
    {  
        if($this->Session->read('User.type')=='admin')
        {
            $this->layout = 'ajax';
            $this->Academic->del($id);
            $this->redirect(array('controller'=>'academics','action'=>'index_admin'));
        }        
    }

}
?>